home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / UTILITY1 / CB200.ZIP / CALEND.PA_ / CALEND.PA
Text File  |  1993-09-01  |  10KB  |  361 lines

  1. Library Calend;
  2.  
  3. { Calend Add-In for the clySmic Icon Bar. (C) 1992, 1993 by clySmic Software.
  4.                                           All Rights reserved. }
  5.  
  6. {define Debug}
  7.  
  8. {$ifndef Debug}
  9. {$R-,I-,D-,L-,S-,V-,W-,G+}
  10. {$endif}
  11.  
  12. {$C MOVEABLE PRELOAD DISCARDABLE}
  13.  
  14. Uses
  15.   WinTypes,WinProcs,Strings,WinDOS,TPWTools;
  16.  
  17. {$R CALEND}
  18. {$I ADD-IN.INC}
  19.  
  20. Const
  21.   ShowDOW : Boolean = True;
  22.   CLBVer : VerString = '2.00';
  23.  
  24. Var
  25.   Yr,Mon,Day,DOW : Word;
  26.   IWDate,INIFile : Array [0..80] of Char;
  27.   USDateFormat : Boolean;
  28.  
  29. {$D Calend Add-In. (C) 1992, 1993 by clySmic Software. All Rights Resv'd.}
  30.  
  31. {-----------------------------------------------}
  32.  
  33. { --- Utility Procedures --- }
  34.  
  35. Function CenterTx(DC : HDC; Tx : PChar; Rect : TRect) : Integer;
  36.  
  37. Var
  38.   Width,WinX,StrtX : Integer;
  39.  
  40. Begin
  41.   { Ask Windows for the total pixel length of the string & calc starting X }
  42.   Width := LoWord(GetTextExtent(DC,Tx,StrLen(Tx)));
  43.  
  44.   { Get total x width of window - don't add 1! }
  45.   WinX := (Rect.Right - Rect.Left);
  46.  
  47.   { Calculate centered starting posn }
  48.   StrtX := ((WinX - Width) Div 2) + Rect.Left;
  49.  
  50.   { Return }
  51.   CenterTx := StrtX;
  52. End {CenterTx};
  53.  
  54. {-----------------------------------------------}
  55.  
  56. Procedure FormIWDate;
  57.  
  58. Const
  59.   MonthName : Array [1..12] of PChar =
  60.     ('January','February','March','April','May','June',
  61.      'July','August','September','October','November','December');
  62.  
  63.   Days : array [0..6] of PChar =
  64.      ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
  65.  
  66. Var
  67.   StrDay,StrYr : Array [0..4] of Char;
  68.  
  69. Begin
  70.   GetDate(Yr,Mon,Day,DOW);
  71.   Str(Day,StrDay);
  72.   Str(Yr,StrYr);
  73.  
  74.   If USDateFormat
  75.     Then Begin
  76.            { US date fmt }
  77.            StrCopy(IWDate,Days[DOW]);
  78.            StrCat(IWDate,', ');
  79.            StrCat(IWDate,MonthName[Mon]);
  80.            StrCat(IWDate,' ');
  81.            StrCat(IWDate,StrDay);
  82.            StrCat(IWDate,', ');
  83.            StrCat(IWDate,StrYr);
  84.          End
  85.     Else Begin
  86.            { European date fmt }
  87.            StrCopy(IWDate,Days[DOW]);
  88.            StrCat(IWDate,', ');
  89.            StrCat(IWDate,StrDay);
  90.            StrCat(IWDate,' ');
  91.            StrCat(IWDate,MonthName[Mon]);
  92.            StrCat(IWDate,' ');
  93.            StrCat(IWDate,StrYr);
  94.          End;
  95. End {FormIWDate};
  96.  
  97. {-----------------------------------------------}
  98.  
  99. { --- Perform Add-In's initialization --- }
  100.  
  101. Function AddInInit(CurVer : PChar) : InitResult; Export;
  102.  
  103. Begin
  104.   { Version check }
  105.   If StrComp(CurVer,CLBVer) <> 0
  106.     Then AddInInit := InitNotOk
  107.     Else AddInInit := InitOk;
  108.  
  109.   { Point at our INI file, which is in our home dir }
  110.   StrPCopy(INIFile,HomeDir);
  111.   StrCat(INIFile,'CALEND.INI');
  112.  
  113.   { Flush INI file so we can edit it }
  114.   WritePrivateProfileString(Nil,Nil,Nil,INIFile);
  115.  
  116.   { Get display mode }
  117.   USDateFormat := Boolean(GetPrivateProfileInt('Settings',
  118.                                                'USDateFormat',
  119.                                                0,
  120.                                                INIFile));
  121. End {AddInInit};
  122.  
  123. {-----------------------------------------------}
  124.  
  125. { --- Paint on the button (Clysbar does the background) --- }
  126.  
  127. Procedure AddInPaint(Wnd : HWnd; DC : HDC; Pressed : Boolean); Export;
  128.  
  129. Const
  130.   MonthName : Array [1..12] of PChar =
  131.     ('JAN','FEB','MAR','APR','MAY','JUN',
  132.      'JUL','AUG','SEP','OCT','NOV','DEC');
  133.  
  134.   Days : array [0..6] of PChar =
  135.      ('SUN','MON','TUE','WED','THU','FRI','SAT');
  136.  
  137. Var
  138.   ShadRect,Rect : TRect;
  139.   NumFont,OldFont,SmlFont : HFont;
  140.   Tx : Array[0..128] of Char;
  141.   StrYr,StrDay : Array [0..4] of Char;
  142.   StrtX,StrtY : Integer;
  143.   TheIcon : HIcon;
  144.  
  145. Begin
  146.   GetClientRect(Wnd,Rect);
  147.  
  148.   { Calc location of icon }
  149.   StrtX := ((Rect.Right - Rect.Left) - GetSystemMetrics(sm_cxIcon)) Div 2;
  150.   StrtY := ((Rect.Bottom - Rect.Top) - GetSystemMetrics(sm_cyIcon)) Div 2;
  151.  
  152.   { Draw turning page if pressed }
  153.   If Pressed
  154.     Then Begin
  155.            TheIcon := LoadIcon(hInstance,'turning');
  156.            DrawIcon(DC,StrtX,StrtY,TheIcon);
  157.  
  158.            Exit;
  159.          End;
  160.  
  161.   { Draw "page" icon }
  162.   TheIcon := LoadIcon(hInstance,'calend');
  163.   DrawIcon(DC,StrtX,StrtY,TheIcon);
  164.  
  165.   { Get date info }
  166.   GetDate(Yr,Mon,Day,DOW);
  167.   Str(Day,StrDay);
  168.   Str(Yr,StrYr);
  169.  
  170.   { Create small font for the month/day/year }
  171.   SmlFont :=
  172.   CreateFont(9,             { Height }
  173.              0,0,0,         { Width, left 2 right, normal orientation }
  174.              400,           { Weight }
  175.              0,0,0,         { Italic, underlined, or strikeout }
  176.              0,             { ANSI char set }
  177.              0,             { Reserved precision field }
  178.              0,             { Default clipping }
  179.              Proof_Quality, { Quality }
  180.              ff_Roman Or Variable_Pitch,
  181.              'Small Fonts');
  182.  
  183.   { Create large font for the day number }
  184.   NumFont :=
  185.   CreateFont(17,            { Height }
  186.              0,0,0,         { Width, left 2 right, normal orientation }
  187.              700,           { Weight }
  188.              0,0,0,         { Italic, underlined, or strikeout }
  189.              0,             { ANSI char set }
  190.              0,             { Reserved precision field }
  191.              0,             { Default clipping }
  192.              Proof_Quality, { Quality }
  193.              ff_Roman Or Variable_Pitch,
  194.              'Times New Roman');
  195.  
  196.   { Setup for day number }
  197.   OldFont := SelectObject(DC,NumFont);
  198.   SetBkMode(DC,Transparent);
  199.  
  200.   { Draw lg day number's shadow }
  201.   SetTextColor(DC,RGB(128,128,128));
  202.   ShadRect := Rect;
  203.   OffsetRect(ShadRect,2,1);
  204.   DrawText(DC,StrDay,StrLen(StrDay),ShadRect,
  205.            dt_Center or dt_VCenter or dt_SingleLine);
  206.  
  207.   { Draw lg day number }
  208.   SetTextColor(DC,RGB(0,0,0));
  209.   OffsetRect(Rect,1,0);
  210.   DrawText(DC,StrDay,StrLen(StrDay),Rect,
  211.            dt_Center or dt_VCenter or dt_SingleLine);
  212.  
  213.   { Setup for other info }
  214.   SelectObject(DC,SmlFont);
  215.  
  216.   { Draw month name }
  217.   StrCopy(Tx,MonthName[Mon]);
  218.   SetTextColor(DC,RGB(255,0,0));
  219.   OffsetRect(Rect,-1,0);
  220.   TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 1,Tx,StrLen(Tx));
  221.  
  222.   { Either year or doy }
  223.   If ShowDOW
  224.     Then Begin
  225.            { Display day of week }
  226.            StrCopy(Tx,Days[DOW]);
  227.            SetTextColor(DC,RGB(0,0,128));
  228.            OffsetRect(Rect,-1,0);
  229.            TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 22,Tx,StrLen(Tx));
  230.          End
  231.     Else Begin
  232.            { Display year }
  233.            StrCopy(Tx,StrYr);
  234.            SetTextColor(DC,RGB(128,0,128));
  235.            TextOut(DC,CenterTx(DC,Tx,Rect),StrtY + 22,Tx,StrLen(Tx));
  236.          End;
  237.  
  238.   { Clean up }
  239.   SelectObject(DC,OldFont);
  240.   DeleteObject(SmlFont);
  241.   DeleteObject(NumFont);
  242. End {AddInPaint};
  243.  
  244. {-----------------------------------------------}
  245.  
  246. { --- Tell Clysbar what kind of timer we need --- }
  247.  
  248. Function AddInTimerNeeded : Integer; Export;
  249.  
  250. Begin
  251.   AddInTimerNeeded := ait_Slow;
  252. End {AddInTimerNeeded};
  253.  
  254. {-----------------------------------------------}
  255.  
  256. { --- Proc called when timer expires, perform timed duties --- }
  257.  
  258. Procedure AddInTimerTick(Wnd : HWnd; DC : HDC); Export;
  259.  
  260. Var
  261.   TimerDay : Word;
  262.  
  263. Begin
  264.   { Check for a date change }
  265.   GetDate(Yr,Mon,TimerDay,DOW);
  266.  
  267.   { If different, repaint window }
  268.   If TimerDay <> Day
  269.     Then AddInPaint(Wnd,DC,False);
  270.  
  271. End {AddInTimerTick};
  272.  
  273. {-----------------------------------------------}
  274.  
  275. { --- Proc called when button pressed --- }
  276.  
  277. Procedure AddInPressed(Wnd : HWnd; DC : HDC); Export;
  278.  
  279. Begin
  280.   { Toggle the "show day-of-week" indicator when button pressed }
  281.   ShowDOW := Not ShowDOW;
  282.   AddInPaint(Wnd,DC,False);
  283. End {AddInPressed};
  284.  
  285. {-----------------------------------------------}
  286.  
  287. { --- Exit processing for Add-In --- }
  288.  
  289. Procedure AddInExit; Export;
  290.  
  291. Begin
  292. End {AddInExit};
  293.  
  294. {-----------------------------------------------}
  295.  
  296. { --- Clysbar queries Add-In about itself --- }
  297.  
  298. Procedure AddInAbout(Str1,Str2 : PChar;
  299.                      Var TheIcon : HIcon;
  300.                      Var TitleCol,TxCol,BkCol : TColorRef); Export;
  301.  
  302. Begin
  303.   StrCopy(Str1,'Calend V2.00');
  304.   StrCopy